package com.zzptc.syl.a1015;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {
    Button btnlogin;
    Button btnreg;
    EditText etname;
    EditText etpsw;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();//实例化控件
        event();//处理事件
    }

    private void event() {
        //注册
        btnreg.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //Toast.makeText(MainActivity.this, "注册", Toast.LENGTH_SHORT).show();
                //创建intent(跳转)
                Intent intent=new Intent(MainActivity.this,RegActivity.class);
                startActivityForResult(intent,1);
            }
        });
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode==1&&resultCode==2){
            String name = data.getStringExtra("name");
            Toast.makeText(this, ""+name, Toast.LENGTH_SHORT).show();
        }
    }

    private void initView() {
        btnlogin=findViewById(R.id.btn_login);
        btnreg=findViewById(R.id.btn_reg);
        etname=findViewById(R.id.et_name);
        etpsw=findViewById(R.id.et_psw);
    }
}
